package com.ctshk.sapp.order.custom.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.rpc.order.custom.dto.order.PreviewInsuranceReceiptDTO;
import com.ctshk.rpc.order.custom.req.order.PreviewInsuranceReceiptReq;
import com.ctshk.rpc.order.custom.req.order.UpdateInsuranceReceiptReq;
import com.ctshk.rpc.order.custom.service.ICustomizedOrderReceiptInsuranceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 保单收据 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-05
 */
@Api(value="保单收据", tags="保单收据")
@RestController
@Slf4j
@RequestMapping("/customized-order-receipt-insurance")
public class CustomizedOrderReceiptInsuranceController extends BaseController {

    @DubboReference
    private ICustomizedOrderReceiptInsuranceService orderReceiptInsuranceService;


    @ApiOperation(value = "保单收据预览", notes = "保单收据预览（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "收據管理-保单收据预览", operDesc = "收據管理-保单收据预览")
    @PostMapping("/preview")
    public Result<PreviewInsuranceReceiptDTO> preview(@RequestBody @Valid PreviewInsuranceReceiptReq req) {
        try {
            return orderReceiptInsuranceService.previewInsurance(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value = "修改保单收据", notes = "修改保单收据（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "修改保单收据", operDesc = "修改保单收据")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid UpdateInsuranceReceiptReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderReceiptInsuranceService.update(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


}
